package com.mysher.devlib.uvc.renderer;

import android.content.Context;
import android.opengl.GLSurfaceView;
import android.util.AttributeSet;

public class YuvGLSurfaceView extends GLSurfaceView {

    private YuvGLRenderer glRenderer;

    public YuvGLSurfaceView(Context context) {
        super(context);
        init();
    }

    public YuvGLSurfaceView(Context context, AttributeSet attrs) {
        super(context, attrs);
        init();
    }

    private void init() {
        setEGLContextClientVersion(2);
        glRenderer = new YuvGLRenderer();
        setRenderer(glRenderer);
        setRenderMode(RENDERMODE_WHEN_DIRTY);
    }

    public void setYUVData(byte[] nv12, int width, int height) {
        if (glRenderer != null) {
            glRenderer.setYuvDataSize(width, height);
            if (nv12 != null) {
                glRenderer.feedData(nv12, 1);
            }
            requestRender();
        }
    }

    @Override
    public void onPause() {
        super.onPause();
    }
}
